package com.source.baseData.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.source.baseData.entity.SlaughterHouse;
import com.source.baseData.entity.SlaughterHouseRepair;
import com.source.baseData.mapper.SlaughterHouseRepairMapper;
import com.source.baseData.service.SlaughterHouseRepairService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.source.baseData.vo.SlaughterHouseRepairVo;
import com.source.savings.Saving;
import com.source.sys.entity.User;
import com.source.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author IceBerg777
 * @since 2021-03-21
 */
@Service
public class SlaughterHouseRepairServiceImpl extends ServiceImpl<SlaughterHouseRepairMapper, SlaughterHouseRepair> implements SlaughterHouseRepairService {

    @Autowired
    SlaughterHouseRepairMapper houseRepairMapper;

    @Autowired
    Saving saving;

    @Override
    public IPage<SlaughterHouseRepairVo> findAll(Page<SlaughterHouseRepairVo> page) {
        return houseRepairMapper.findAll(page);
    }

    @Override
    public IPage<SlaughterHouseRepairVo> findByHouseId(String houseId, Page<SlaughterHouseRepairVo> page) {
        return houseRepairMapper.findByHouseId(houseId,page);
    }

    @Override
    public List<SlaughterHouseRepairVo> findByHouseId(String houseId) {

        return houseRepairMapper.findByHouseId(houseId);
    }

    @Override
    public List<SlaughterHouseRepairVo> findByKeyWord(String keyWord) {
        return houseRepairMapper.findByKeyWord(keyWord);
    }

    @Override
    public List<User> findUnSavedHouseRepairsByHouseId(String houseId) {
        CommonResult<List<User>> allRepairs = saving.findAllRepairs();
        List<User> repairsData = allRepairs.getData();
        List<SlaughterHouseRepairVo> byHouseId = findByHouseId(houseId);
        //获取两个list，根据id相减
        for (SlaughterHouseRepairVo slaughterHouseRepairVo : byHouseId) {
            for (User repairsDatum : repairsData) {
                if(repairsDatum.getUserId().equals(slaughterHouseRepairVo.getUserId())){
                    repairsData.remove(repairsDatum);
                    break;
                }
            }
        }
        return repairsData;
    }

    @Override
    public List<SlaughterHouseRepairVo> findDistinct() {
        return houseRepairMapper.findDistinct();
    }

    @Override
    public List<SlaughterHouse> findUnAdded() {
        return houseRepairMapper.findUnAdded();
    }
}
